package com.cddx.logistics.controller;

import com.cddx.logistics.domain.dto.VehicleTaskQueryDTO;
import com.cddx.logistics.domain.pojo.VehicleTask;
import com.cddx.logistics.domain.vo.VehicleTaskVO;
import com.cddx.logistics.service.VehicleTaskService;
import com.cddx.logistics.util.model.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/vehicleTask")
@Api(tags = "车辆任务管理")
public class VehicleTaskController {
    @Resource
    private VehicleTaskService vehicleTaskService;

    @GetMapping("/queryByDate")
    @ApiOperation("按日期查询任务")
    public R queryByDate(VehicleTaskQueryDTO queryDTO) {
        List<VehicleTaskVO> list = vehicleTaskService.queryByDate(queryDTO);
        return R.ok(list);
    }

    @GetMapping("/queryPage")
    @ApiOperation("分页查询任务")
    public R queryPage(VehicleTaskQueryDTO queryDTO) {
        PageInfo<VehicleTaskVO> pageInfo = vehicleTaskService.queryPage(queryDTO);
        return R.ok(pageInfo);
    }

    @PostMapping("/add")
    @ApiOperation("添加任务")
    public R add(@RequestBody VehicleTask vehicleTask) {
        return vehicleTaskService.add(vehicleTask) ? R.ok("添加成功") : R.error("添加失败");
    }

    @PostMapping("/update")
    @ApiOperation("修改任务")
    public R update(@RequestBody VehicleTask vehicleTask) {
        return vehicleTaskService.update(vehicleTask) ? R.ok("修改成功") : R.error("修改失败");
    }

    @GetMapping("/delete")
    @ApiOperation("删除任务")
    public R delete(Integer id) {
        return vehicleTaskService.delete(id) ? R.ok("删除成功") : R.error("删除失败");
    }
}